package study;

import java.util.Random;
import java.util.Scanner;

public class Addiction {
    private Random r;
    public int score;
    private int num;
    private Scanner scan;
    public Addiction(int num) {
        r = new Random();
        score = 0;
        this.num = num;
        scan = new Scanner(System.in);
    }
    public Addiction() {
        this(10);
    }
    public void test() {
        long start = System.currentTimeMillis();
        for(int i = 0, a, b, c; i < num; i++) {
            a = r.nextInt(100);
            b = r.nextInt(100);
            System.out.print(a + " + " + b + " = ");
            c = scan.nextInt();
            if( a + b == c)
                score += 10;
            else
                System.out.println("错了，正确答案是：" + (a + b));
        }
        long time = System.currentTimeMillis() - start;
        String str = (time % 1000) + "毫秒";
        time /= 1000;
        if(time != 0) {
            str = (time % 60) + "秒，" + str;
            time /= 60;
            if(time != 0)
                str = time + "分，" + str;
        }
        System.out.println("您的得分：" + score + "\n耗时：" + str);
        scan.close();
    }
    public static void main(String[] args) {
        new Addiction().test();
    }
}
